<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-sub-content">
  <form name="supportTicketCtrl.formTicket" ng-submit="supportTicketCtrl.create()" novalidate>
    <div class="gv-forms" layout="column">
      <div class="gv-forms-header">
        <h1>Support ticket creation</h1>
        <a ui-sref="management.support.tickets">See tickets history</a>
      </div>
      <h5 ng-if="!supportTicketCtrl.userHasAnEmail" style="color: red; margin-left: 10px">
        <ng-md-icon icon="warning" class="gv-warning"></ng-md-icon>
        <span>You can not submit a ticket because you do not have an email configured on your account</span>
      </h5>

      <div class="gv-form">
        <h2></h2>
        <div class="gv-form-content" layout="column" style="background-color: #fafafa">
          <md-input-container ng-if="!supportTicketCtrl.stateParams.apiId">
            <label>Select an API</label>
            <md-select ng-model="supportTicketCtrl.ticket.api" ng-disabled="!supportTicketCtrl.userHasAnEmail">
              <md-option ng-repeat="api in supportTicketCtrl.apis" ng-value="api.id">{{api.name}} ({{api.version}})</md-option>
            </md-select>
          </md-input-container>
          <md-input-container>
            <label>Select an application</label>
            <md-select ng-model="supportTicketCtrl.ticket.application" ng-disabled="!supportTicketCtrl.userHasAnEmail">
              <md-option ng-repeat="application in supportTicketCtrl.applications" ng-value="application.id"
                >{{application.name}} ({{application.owner.displayName}})</md-option
              >
            </md-select>
          </md-input-container>
          <md-input-container>
            <label>Subject</label>
            <input ng-model="supportTicketCtrl.ticket.subject" ng-required="true" ng-disabled="!supportTicketCtrl.userHasAnEmail" />
          </md-input-container>
          <md-input-container>
            <label>Content</label>
            <textarea
              ng-model="supportTicketCtrl.ticket.content"
              ng-required="true"
              rows="10"
              ng-disabled="!supportTicketCtrl.userHasAnEmail"
            ></textarea>
          </md-input-container>
          <md-input-container>
            <md-checkbox
              ng-model="supportTicketCtrl.ticket.copyToSender"
              ng-disabled="!supportTicketCtrl.userHasAnEmail"
              aria-label="cb-copy-to-sender"
            >
              <span>Receive a copy of the email</span>
            </md-checkbox>
          </md-input-container>

          <div class="md-actions" layout="row">
            <md-button
              type="submit"
              class="md-raised md-primary"
              ng-disabled="supportTicketCtrl.formTicket.$pristine || supportTicketCtrl.formTicket.$invalid || !supportTicketCtrl.userHasAnEmail"
              aria-label="create-ticket"
              >Create</md-button
            >
          </div>
        </div>
      </div>
    </div>
  </form>
</div>
